//
//  XLSwitchCompanyView.m
//  industry
//
//  Created by xl on 2020/11/26.
//  Copyright © 2020 Haier. All rights reserved.
//

#import "XLSwitchCompanyView.h"
#import "XLSwitchCompanyViewProtocol.h"
#import "XLSwitchCompanyAdapter.h"
#import "XLSwitchCompanyPresenterProtocol.h"

@interface XLSwitchCompanyView ()<XLSwitchCompanyViewProtocol, XLAdapterDelegate>

@property (nonatomic, strong) XLTableView *tableView;
@property (nonatomic, strong) XLSwitchCompanyAdapter *adapter;

@end
@implementation XLSwitchCompanyView

- (void)dealloc {
    XLLog(@"XLSwitchCompanyView dealloc");
}

#pragma mark - XLSwitchCompanyViewProtocol
- (void)buildView {
    [self addSubview:self.tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(self);
    }];
    
    
    XLSend(self.baseController.presenter, XLSwitchCompanyPresenterProtocol, requestCompanyList);
}

- (void)refreshTableView:(NSArray *)dataArr {
    [_adapter setAdapterArray:dataArr];
    [_tableView reloadData];
}
#pragma mark - XLAdapterDelegate
- (void)didSelectCellData:(id)cellData {
    XLSend(self.baseController.presenter, XLSwitchCompanyPresenterProtocol, handleCellData:cellData);
}

#pragma mark - Setter/getter
- (XLTableView *)tableView {
    if (!_tableView) {
        _tableView = [[XLTableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.backgroundColor = [UIColor whiteBgColor];
        _tableView.delegate = self.adapter;
        _tableView.dataSource = self.adapter;
        _tableView.tableFooterView = [UIView new];
    }
    return _tableView;
}

- (XLSwitchCompanyAdapter *)adapter {
    if (!_adapter) {
        _adapter = [[XLSwitchCompanyAdapter alloc] init];
        _adapter.adapterDelegate = self;
    }
    return _adapter;
}

@end
